R=lambda:map(int,input().split())
n,k=R()
a=sorted(zip(R(),range(n)))[-k:]
print(sum(x[0]for x in a))
b=sorted(x[1]for x in a)+[n]
b[0]=0
print(*(y-x for x,y in zip(b,b[1:])))
#include <iostream>
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{FIO
int n,k;
cin>>n>>k;
int arr[n],arr2[n],max[k],indx[k],sum=0;
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<n;i++)
arr2[i]=arr[i];
sort(arr2,arr2+n,greater<int>());
for(int i=0;i<k;i++){
max[i]=arr2[i];
sum+=arr2[i];
}
if(k==1){
cout<<max[0]<<"\n";
cout<<n;
return 0;
}
for(int i=0;i<k;i++){
for(int j=0;j<n;j++){
if(max[i]==arr[j]){
indx[i]=j;
arr[j]=0;
// max[i]=0;
break;
}
}
}
sort(indx,indx+k);
cout<<sum<<"\n";
int x=-1;int f=0;
for(int i=0;i<k;i++){
//f=f+(indx[i]-x);
if(i==k-1){
if(n-x>=indx[i]-x){
cout<<n-1-x;
break;
}
else {
cout<<indx[i]-x;break;
}
}
cout<<abs(indx[i]-x)<<" ";
f=f+(indx[i]-x);
x=indx[i];
}
/* if(indx[k-1]-x<n-f)
cout<<n-f;
else cout<<indx[k-1]-x;*/
return 0;
}
566. Reshape the Matrix | 167. Two Sum II - Input array is sorted |
387. First Unique Character in a String | 383. Ransom Note |
242. Valid Anagram | 141. Linked List Cycle |
21. Merge Two Sorted Lists | 203. Remove Linked List Elements |
733. Flood Fill | 206. Reverse Linked List |
83. Remove Duplicates from Sorted List | 116. Populating Next Right Pointers in Each Node |
145. Binary Tree Postorder Traversal | 94. Binary Tree Inorder Traversal |
101. Symmetric Tree | 77. Combinations |
46. Permutations | 226. Invert Binary Tree |
112. Path Sum | 1556A - A Variety of Operations |
136. Single Number | 169. Majority Element |
119. Pascal's Triangle II | 409. Longest Palindrome |
1574A - Regular Bracket Sequences | 1574B - Combinatorics Homework |
1567A - Domino Disaster | 1593A - Elections |
1607A - Linear Keyboard | EQUALCOIN Equal Coins |